import baseService from '@/utils/http/axios'

const baseUrl = import.meta.env.VITE_APP_BASE_API

// 查询文章
export const getPostsApi = (params) => {
  return baseService({
    url: baseUrl + `/posts`,
    method: 'get',
    params
  })
}

// 获取指定文章
export const getPostsById = (params) => {
  return baseService({
    url: baseUrl + `/posts/${params.id}`,
    method: 'get'
  })
}

// 创建文章
export const createPostApi = (data) => {
  return baseService({
    url: baseUrl + '/posts',
    method: 'post',
    data
  })
}

// 删除文章
export const deletePostApi = (data) => {
  return baseService({
    url: baseUrl + `/posts/${data.id}`,
    method: 'delete'
  })
}

// 更新文章
export const updatePostApi = (data) => {
  return baseService({
    url: baseUrl + `/posts/${data.id}`,
    method: 'put',
    data
  })
}
